--[[模拟器分辨率：760*400 DPI：106
	脚本入口函数： Main(dm_OBJ,hwnd)
	dm_OBJ：大漠对象
	hwnd：模拟器主窗口句柄
	Main函数末尾加return xxx
	xxx：可自定义任何反馈给主程序的值，不能为nil
	*脚本过程中使用的大漠函数名、参数等参照大漠说明文档
]]

function currDir()
  os.execute("cd > cd.tmp")
  local f = io.open("cd.tmp", r)
  local cwd = f:read("*a")
  f:close()
  os.remove("cd.tmp")
  cwd= string.sub(cwd, 1, -2)
  print(cwd)
  return cwd
end


function md5_sumhexa(k)
	str = currDir()
	str = str .. '\\md5core.dll'
	local md5_core = package.loadlib(str,"luaopen_md5_core")
	
	--local md5_core = require "md5core"
	--k = md5_core.sum(k)
	l= md5_core()
	----[[
	k = l.sum(k)
	return (string.gsub(k, ".", 
		function (c) 
			return string.format("%02x", string.byte(c)) 
		end
		)
	)
	--]]
	--crypt
	--[[
	for k1, v in pairs(l) do
		
		print(k1,v)
	end
	
	--]]
	
end

function ToBase64(source_str)
    local b64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
    local s64 = ''
    local str = source_str

    while #str > 0 do
        local bytes_num = 0
        local buf = 0

        for byte_cnt=1,3 do
            buf = (buf * 256)
            if #str > 0 then
                buf = buf + string.byte(str, 1, 1)
                str = string.sub(str, 2)
                bytes_num = bytes_num + 1
            end
        end

        for group_cnt=1,(bytes_num+1) do
            b64char = math.fmod(math.floor(buf/262144), 64) + 1
            s64 = s64 .. string.sub(b64chars, b64char, b64char)
            buf = buf * 64
        end

        for fill_cnt=1,(3-bytes_num) do
            s64 = s64 .. '='
        end
    end

    return s64
end

function FromBase64(str64)
    local b64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
    local temp={}
    for i=1,64 do
        temp[string.sub(b64chars,i,i)] = i
    end
    temp['=']=0
    local str=""
    for i=1,#str64,4 do
        if i>#str64 then
            break
        end
        local data = 0
        local str_count=0
        for j=0,3 do
            local str1=string.sub(str64,i+j,i+j)
            if not temp[str1] then
                return
            end
            if temp[str1] < 1 then
                data = data * 64
            else
                data = data * 64 + temp[str1]-1
                str_count = str_count + 1
            end
        end
        for j=16,0,-8 do
            if str_count > 0 then
                str=str..string.char(math.floor(data/math.pow(2,j)))
                data=math.mod(data,math.pow(2,j))
                str_count = str_count - 1
            end
        end
    end
    return str
end





function Split(str, delim, maxNb)  --分割字符串
    -- Eliminate bad cases...  
    if string.find(str, delim) == nil then 
        return { str } 
    end 
    if maxNb == nil or maxNb < 1 then 
        maxNb = 0    -- No limit  
    end 
    local result = {} 
    local pat = "(.-)" .. delim .. "()"  
    local nb = 0 
    local lastPos  
    for part, pos in string.gfind(str, pat) do 
        nb = nb + 1 
        result[nb] = part  
        lastPos = pos  
        if nb == maxNb then break end 
    end 
    if nb ~= maxNb then 
        result[nb + 1] = string.sub(str, lastPos)  
    end 
    return result  
end 



function readAccount() -- 读取本地账号密码
	local acctountTable = {}
	local sTable = {}
	local myFlie = io.open("qq.txt","r")
	if myFlie == nil then
		print("打开文件出错")
	else
		print("打开文件成功，可以进行读取操作\n")
		while true do
		line = myFlie:read("*l")
			if line == nil  then
				break
			end
			
			print(line)
			
			sTable = Split(line,"-")
			
			table.insert(acctountTable,sTable)
			
		end
	end
	myFlie:close()
	
	
	return acctountTable
end
function readtxt(dm_OBJ,rcpath,hwnd,ltype) -- 读取本地账号密码
	local line = ""
	local title = dm_OBJ:GetWindowTitle(tonumber(hwnd))
	
	line = dm_OBJ:ReadIni("kingRobot.lua",ltype,rcpath..title..".ini")
		
	return line
end



function ParseCoord(str)  --返回由索引1开始的值，retStr[1][2] == -1 则找不到图
	local retStr = {}
	local temprStr = {}
	temprStr = Split(str, '|')
	for i = 1,#temprStr do
		retStr[i] = Split(temprStr[i], ",")
	end
	return retStr
end

function FindPicCheck(dm_OBJ,x1, y1, x2, y2, pic_name, delta_color,sim,f_type)
	local pic_ret
	local coord = {}
	pic_ret = dm_OBJ:FindPicEx(x1, y1, x2, y2, pic_name, delta_color,sim, 0)
	coord = ParseCoord(pic_ret)
    if tonumber(coord[1][2]) > 0 then
		if f_type == "click" then
			dm_OBJ:MoveTo(tonumber(coord[1][2]),tonumber(coord[1][3]))
			dm_OBJ:LuaSleep(1000)
			dm_OBJ:LeftClick()
			return true
		elseif f_type == "ret" then
			return ret
		end
	else
		pic_ret = nil
	end
	return pic_ret
end

function Outcry(dm_OBJ,hwnd,connet,num)
	--查找英雄的标志
	--wzry_outcry_heroTip.bmp
	local tempNum = 0
	--循环喊话任务
	while true do	
		local ret =dm_OBJ:FindPicEx(0,0,2000,2000,"wzry_outcry_heroTip.bmp","050505",0.75,0)	
		if ret ~= "" then
			inputLog("找到英雄的标志")
			stable = Split(ret,",")
			if(tonumber(stable[2])>0) then
				dm_OBJ:MoveTo(tonumber(stable[2])+30,tonumber(stable[3])-30)
				dm_OBJ:LuaSleep(1000)
				dm_OBJ:LeftClick()
				--查找麦克风开始
				while true do
					--查找麦克风的标志

					
					
					--c63839-050505
					--FindColorEx
					ret =dm_OBJ:FindColorEx(62,398,181,423,"ab3335-050505|bd3737-050505",0.9,0)
				
					if ret ~= "" then
						inputLog("喊话等待..")
						dm_OBJ:LuaSleep(1000)	
					else		
						inputLog("开始喊话,内容为:" .. connet )
						ret =dm_OBJ:FindPicEx(0,0,2000,2000,"wzry_outcry_mic.bmp","050505",0.8,0)	
						if ret ~= "" then
							stable = Split(ret,",")
							if (tonumber(stable[2])>0) then
								dm_OBJ:MoveTo(tonumber(stable[2])+70,tonumber(stable[3])+10)
								dm_OBJ:LuaSleep(1000)
								dm_OBJ:LeftClick()
								dm_OBJ:LuaSleep(1000)
								dm_OBJ:KeyPress(8)
								dm_OBJ:LuaSleep(1000)
								dm_OBJ:SendString(tonumber(hwnd),connet..tostring(tempNum))
								dm_OBJ:LuaSleep(1000)
								while true do
									--查找确定按钮
									ret =dm_OBJ:FindPicEx(0,0,2000,2000,"wzry_outcry_ascertain.bmp","050505",0.8,0)	
									if ret ~= "" then
										stable = Split(ret,",")
										if (tonumber(stable[2])>0) then
											dm_OBJ:MoveTo(tonumber(stable[2])+5,tonumber(stable[3])+5)
											dm_OBJ:LuaSleep(1000)
											dm_OBJ:LeftClick()
											dm_OBJ:LuaSleep(1000)
											while true do
											inputLog("发送消息")
												ret =dm_OBJ:FindPicEx(0,0,2000,2000,"wzry_outcry_send.bmp","050505",0.8,0)
												if ret ~= "" then
													stable = Split(ret,",")
													if (tonumber(stable[2])>0) then
														dm_OBJ:MoveTo(tonumber(stable[2])+5,tonumber(stable[3])+5)
														dm_OBJ:LuaSleep(1000)
														dm_OBJ:LeftClick()
														dm_OBJ:LuaSleep(1000)
														break
													end
												end
											
											end
											
											break
										end
									end
									
									dm_OBJ:LuaSleep(1000)
								end
								
								
								tempNum = tempNum+1
							end
							
							
							
						dm_OBJ:LuaSleep(1000)	
						end
						
					end
					
					
					if tempNum>= num then
						inputLog("达到次数,准备退出")
						break
					end
					
				end
				
				
				--这里需要退出聊天窗口
				while true do
				ret =dm_OBJ:FindPicEx(0,0,2000,2000,"wzry_outcry_closeChat.bmp","050505",0.9,0)	
					if ret ~= "" then
						stable = Split(ret,",")
						if (tonumber(stable[2])>0) then
							dm_OBJ:MoveTo(tonumber(stable[2])+5,tonumber(stable[3])+5)
							dm_OBJ:LuaSleep(1000)
							dm_OBJ:LeftClick()
							dm_OBJ:LuaSleep(1000)
							break
							
						end
					
					end
				
				
				end
				
				return "break the loop"	
		
					
				
			end
				
				
				--return "break the loop"
				--结束查找麦克风
		else
				inputLog("关闭所有干扰")
				--关闭所有干扰
			while true do
				
				--wzry_loaded_closeWindow.bmp
				dm_OBJ:LuaSleep(1000)	
				ret = dm_OBJ:FindPicEx(334,33,722,131,"wzry_loaded_closeWindow.bmp","050505",0.7,0)	
				if ret ~= "" then
					stable = Split(ret,",")
			
					if(tonumber(stable[2])>0) then
					--Found this pic ,click this pic
					dm_OBJ:MoveTo(tonumber(stable[2]+5),tonumber(stable[3]+5))
					dm_OBJ:LuaSleep(1000)
					dm_OBJ:LeftClick()	
					dm_OBJ:LuaSleep(3000)	
					end		
					
				else
					dm_OBJ:LuaSleep(2000)
					break
				end		
						
			end
		end
	end

	
	
	
	
	
end

function yunDaMa(dm_OBJ,rcpath,hwnd)
	local str = ""
	local damaID = 0
	local d_path = rcpath .. "lua\\rc\\kingRobot\\"
	--打码范围
	--198,156,364,223
	while true do
	--wzry_yundama_enterCodeTip.bmp
		dm_OBJ:LuaSleep(1000)
		ret = dm_OBJ:FindPicEx(367,160,513,218,"wzry_yundama_enterCodeTip.bmp","050505",0.9,0)	
		if ret ~= "" then
			inputLog("开始打码")
			--这里开始截图
			--传图片
			--取识别信息		
			--下面是准备输入信息
			
			while true do
				dm_OBJ:Capture(198,156,364,223,tostring(hwnd)..".bmp")
				
			
				dm_OBJ:LuaSleep(500)
				dm_OBJ:YDM_SetAppInfo(3512,"a2060321e612b8694a53bc1d007ad3b6")
				dm_OBJ:YDM_Login("ycjl520", "weiyudns")
				dm_OBJ:LuaSleep(500)
				damaID = dm_OBJ:YDM_UploadByPath(d_path..tostring(hwnd)..".bmp", 1004)
				dm_OBJ:LuaSleep(3000)
				--return damaID
			--end
				
				while true do
				
					local tempstr = dm_OBJ:YDM_GetResult(tonumber(damaID))
					--return tempstr
					
					local tempTable = {}
					tempTable = Split(tempstr,"|")
					
					if tempTable[1] == "0" then
						str=tempTable[2]	
						break
						
					elseif  tempTable[1] == "-1007"then
						str = "余额不足"	
						break
					end		
					
					dm_OBJ:LuaSleep(1000)		
								
				end
				
				
				if str ~= "" then
					break					
				end
				
				--end
					--return str
			end

			if str ~= "" then
				--这里是点击确认验证码
				
				if str == "余额不足" then
					--67,71
					dm_OBJ:MoveTo(67,71)
					dm_OBJ:LuaSleep(1000)
					dm_OBJ:LeftClick()	
					
				else
					dm_OBJ:MoveTo(420,188)
					dm_OBJ:LuaSleep(1000)
					dm_OBJ:LeftClick()	
					dm_OBJ:LuaSleep(1000)	
					dm_OBJ:SendString(tonumber(hwnd),str)
					dm_OBJ:MoveTo(356,330)
					dm_OBJ:LuaSleep(1000)
					dm_OBJ:LeftClick()	
					dm_OBJ:LuaSleep(3000)	
				end
							
			end			
			
			
		else
			inputLog("没有打码")
			break	
			
		end
		
		dm_OBJ:LuaSleep(1000)
	end
	return str
end


function QQLoadAccount(dm_OBJ,rcpath,hwnd,name,password)
	inputLog(name)
	inputLog(password)
	local str = ""
	dm_OBJ:LuaSleep(1000)
	local ret = dm_OBJ:FindPicEx(0,0,2000,2000,"wzry_desktop.bmp","050505",0.8,0)
	if ret ~= "" then
		stable = Split(ret,",")	
		if(tonumber(stable[2])>0) then
			inputLog("找到了桌面图标")
			inputLog(ret)
			--Found this pic ,click this pic
			dm_OBJ:MoveTo(tonumber(stable[2]),tonumber(stable[3]))
			dm_OBJ:LuaSleep(1000)
			dm_OBJ:LeftClick()
			--wait for QQload pic tip 
			while true do
				ret = dm_OBJ:FindPicEx(0,0,2000,2000,"wzry_load_QQTip.bmp","050505",0.8,0)			
				if ret ~= "" then
					-- Found this pic tip, click this pic
					inputLog("找到了登陆按钮")
					stable = Split(ret,",")				
					if(tonumber(stable[2])>0) then
						dm_OBJ:MoveTo(tonumber(stable[2]),tonumber(stable[3]))
						dm_OBJ:LuaSleep(1000)
						dm_OBJ:LeftClick()
						--wait QQload tip the pic 
						while true do
							--wzry_QQload_Tip.bmp
							ret = dm_OBJ:FindPicEx(0,0,2000,2000,"wzry_QQload_Tip.bmp|wzry_QQload_Tip1.bmp","050505",0.8,0)	
												
							if ret ~= "" then
								inputLog("找到了QQ登陆提示")
								inputLog(ret)
								-- found this pic ,click this pic offer the your size
								stable = Split(ret,",")
								--120,40
								if tonumber(stable[2])>0 then
									dm_OBJ:MoveTo(tonumber(stable[2])+120,tonumber(stable[3])+40)
									dm_OBJ:LuaSleep(1000)
									dm_OBJ:LeftClick()									
								end
								
								--wait the 
								while true do
								
								--wzry_account_init.bmp
									ret = dm_OBJ:FindPicEx(0,0,2000,2000,"wzry_account_init.bmp","050505",0.8,0)	
									if ret ~= "" then	
										inputLog("找到输入账号的文本框")
										stable = Split(ret,",")
										if tonumber(stable[2])>0 then
												--120,40
											dm_OBJ:MoveTo(tonumber(stable[2])+10,tonumber(stable[3]))
											dm_OBJ:LuaSleep(1000)
											dm_OBJ:LeftClick()
											dm_OBJ:LuaSleep(1000)										
											
											dm_OBJ:SendString(tonumber(hwnd),name)
											dm_OBJ:LuaSleep(1000)
											--return myAccountTable[1][2]
											
											dm_OBJ:MoveTo(tonumber(stable[2]),tonumber(stable[3])+35)
											dm_OBJ:LeftClick()
											dm_OBJ:LuaSleep(1000)
											dm_OBJ:SendString(tonumber(hwnd),password)
											inputLog("输入密码完毕")
											dm_OBJ:LuaSleep(1000)
											dm_OBJ:MoveTo(tonumber(stable[2]),tonumber(stable[3])+60)
											dm_OBJ:LeftClick()
											dm_OBJ:LuaSleep(5000)
											inputLog("已经登陆")
											str = yunDaMa(dm_OBJ,rcpath,hwnd)
											inputLog("已经打码完毕")
											if str == "余额不足" then
												
												return str
											end
										end
										
										inputLog("准备查找开始按钮")
										while true do
											dm_OBJ:LuaSleep(1000)
											ret = dm_OBJ:FindPicEx(0,0,2000,2000,"wzry_load_startGame.bmp","050505",0.8,0)
											if ret ~= "" then
												--368,358
												inputLog("开始游戏")
												dm_OBJ:MoveTo(368,358)
												dm_OBJ:LuaSleep(1000)
												dm_OBJ:LeftClick()
												dm_OBJ:LuaSleep(1000)
												
												break 
											else
											
												ret = dm_OBJ:FindPicEx(0,0,2000,2000,"wzry_load_myserver.bmp","050505",0.8,0)
												if ret ~= "" then
													inputLog("找到了我的服务")
													dm_OBJ:MoveTo(207,159)
													dm_OBJ:LuaSleep(1000)
													dm_OBJ:LeftClick()
													dm_OBJ:LuaSleep(1000)
												end
												
												
											end
											
											--clearAccount(dm_OBJ)
											---------------------------------------
											--清除数据
											dm_OBJ:LuaSleep(3000)
											ret = dm_OBJ:FindPicEx(0,0,2000,2000,"wzry_QQload_clear.bmp|wzry_QQload_clear1.bmp","151515",0.8,0)
											
											if ret ~= "" then
												inputLog("找到清除信息标志")
												while true do
													inputLog("循环清除数据")
													ret = dm_OBJ:FindPicEx(0,0,2000,2000,"wzry_QQload_clear.bmp|wzry_QQload_clear1.bmp","151515",0.8,0)
													inputLog(ret)
													if ret ~= "" then
														stable = Split(ret,"|")
														if stable[2] ~= nil then															
															stable = Split(stable[1],",")
															else
															stable = Split(ret,",")
														end
														
														
														--120,40
														if tonumber(stable[2])>0 then
															dm_OBJ:MoveTo(tonumber(stable[2]+5),tonumber(stable[3]+5))
															dm_OBJ:LuaSleep(1000)
															dm_OBJ:LeftClick()
															dm_OBJ:LuaSleep(1000)
														end
														
													end
													
												
													ret = dm_OBJ:FindPicEx(0,0,2000,2000,"wzry_QQload_clear.bmp|wzry_QQload_clear1.bmp","151515",0.8,0)
													if ret == "" then
														break
													end
													dm_OBJ:LuaSleep(1000)
												end
											inputLog("清除数据完毕!")
											end
											--------------------------------------------------
											
											
											
											
											ret = dm_OBJ:FindPicEx(0,0,2000,2000,"wzry_account_init.bmp","050505",0.8,0)	
											if ret ~= "" then
												inputLog("重新输入账号密码")
												stable = Split(ret,",")
												if tonumber(stable[2])>0 then
														--120,40
													dm_OBJ:MoveTo(tonumber(stable[2])+10,tonumber(stable[3]))
													dm_OBJ:LuaSleep(1000)
													dm_OBJ:LeftClick()
													dm_OBJ:LuaSleep(1000)										
													
													dm_OBJ:SendString(tonumber(hwnd),name)
													dm_OBJ:LuaSleep(1000)
													--return myAccountTable[1][2]
													
													dm_OBJ:MoveTo(tonumber(stable[2]),tonumber(stable[3])+35)
													dm_OBJ:LeftClick()
													dm_OBJ:LuaSleep(1000)
													dm_OBJ:SendString(tonumber(hwnd),password)
													
													dm_OBJ:LuaSleep(1000)
													dm_OBJ:MoveTo(tonumber(stable[2]),tonumber(stable[3])+60)
													dm_OBJ:LeftClick()
													dm_OBJ:LuaSleep(5000)
													
													str = yunDaMa(dm_OBJ,rcpath,hwnd)
													if str == "余额不足" then
														
														return str
													end
												end
												
											end
																								
											dm_OBJ:LuaSleep(1000)
										end							
										
										break		
										
									
										
									end
									
			
									
									dm_OBJ:LuaSleep(1000)
									
									ret = dm_OBJ:FindPicEx(0,0,2000,2000,"wzry_QQload_clear.bmp","050505",0.8,0)
									
									if ret ~= "" then
										while true do
											ret = dm_OBJ:FindPicEx(0,0,2000,2000,"wzry_QQload_clear.bmp","050505",0.8,0)
											if ret ~= "" then
												stable = Split(ret,",")
												inputLog("清除数据")
												--120,40
												if tonumber(stable[2])>0 then
													dm_OBJ:MoveTo(tonumber(stable[2])+10,tonumber(stable[3])+10)
													dm_OBJ:LuaSleep(1000)
													dm_OBJ:LeftClick()
													dm_OBJ:LuaSleep(1000)
												end
											else
												
												break
											end
											
											
										end
										
										
									
									end
									
									dm_OBJ:LuaSleep(1000)
									
									
									
									--这个是切换账号的图片
									ret = dm_OBJ:FindPicEx(0,0,2000,2000,"wzry_load_replaceAccount.bmp","050505",0.8,0)
									
									if ret ~= "" then
										stable = Split(ret,",")
										--120,40
										dm_OBJ:MoveTo(tonumber(stable[2])+3,tonumber(stable[3])+3)
										dm_OBJ:LuaSleep(1000)
										dm_OBJ:LeftClick()
										dm_OBJ:LuaSleep(1000)
									end
									dm_OBJ:LuaSleep(1000)
								end
								break
							end
							inputLog("没有找到QQ登陆提示")				
							dm_OBJ:LuaSleep(1000)
						end
						
						
					end
					break
				end
				
				ret = dm_OBJ:FindPicEx(0,0,2000,2000,"wzry_load_logout.bmp","050505",0.8,0)	
				if ret ~= "" then
					stable = Split(ret,",")
					--120,40
					dm_OBJ:MoveTo(tonumber(stable[2])+5,tonumber(stable[3])+5)
					dm_OBJ:LuaSleep(1000)
					dm_OBJ:LeftClick()
					dm_OBJ:LuaSleep(1000)
				end
				
				dm_OBJ:LuaSleep(1000)		
			end
			
		end
		else
		inputLog("没有找到桌面图标")
	end
	

end


function clearAccount(dm_OBJ)
	
		dm_OBJ:LuaSleep(3000)
		ret = dm_OBJ:FindPicEx(0,0,2000,2000,"wzry_QQload_clear.bmp|wzry_QQload_clear1.bmp","151515",0.8,0)
		
		if ret ~= "" then
			inputLog("找到清除信息标志")
			while true do
				inputLog("循环清除数据")
				ret = dm_OBJ:FindPicEx(0,0,2000,2000,"wzry_QQload_clear.bmp|wzry_QQload_clear1.bmp","151515",0.8,0)
				inputLog(ret)
				if ret ~= "" then
					stable = Split(ret,"|")
					if stable[2] ~= nil then															
						stable = Split(stable[1],",")
						else
						stable = Split(ret,",")
					end
					
					
					--120,40
					if tonumber(stable[2])>0 then
						dm_OBJ:MoveTo(tonumber(stable[2]+5),tonumber(stable[3]+5))
						dm_OBJ:LuaSleep(1000)
						dm_OBJ:LeftClick()
						dm_OBJ:LuaSleep(1000)
					end
					
				end
				
			
				ret = dm_OBJ:FindPicEx(0,0,2000,2000,"wzry_QQload_clear.bmp|wzry_QQload_clear1.bmp","151515",0.8,0)
				if ret == "" then
					break
				end
				dm_OBJ:LuaSleep(1000)
			end
			inputLog("清除数据完毕!")
		end
	
end
	

function closeApp(dm_OBJ)
	
	
	while true do
		dm_OBJ:MoveTo(741,375)
		dm_OBJ:LuaSleep(1000)
		dm_OBJ:LeftClick()
		dm_OBJ:LuaSleep(2000)
		ret =dm_OBJ:FindPicEx(151,160,532,316,"wzry_closeApp.bmp|wzry_closeApp1.bmp|wzry_closeApp2.bmp","050505",0.75,0)
		if ret ~= "" then
			dm_OBJ:MoveTo(636,251)
			dm_OBJ:LuaSleep(1000)
			dm_OBJ:LeftClick()
			break
		else
			--636,251
			dm_OBJ:MoveTo(636,251)
			dm_OBJ:LuaSleep(1000)
			dm_OBJ:LeftDown()
			--dm_OBJ:LuaSleep(500)
			dm_OBJ:MoveR(0,-100)
			--dm_OBJ:LuaSleep(500)
			dm_OBJ:LeftUp()
			dm_OBJ:LuaSleep(1000)
		end
		dm_OBJ:LuaSleep(1000)
	end
	
end
	
function inputLog(adata)
	--local thisTime = os.time()
	
	
	local data = ""
	local file = io.open("log.txt","r")
	if file ~= nil then
		data = file:read("*a")
		file:close()	
	
		
	end
	
	file = io.open("log.txt","w")
	file:write(data.. "\n" ..adata)
	file:close()
	
end

function Main(dm_OBJ,hwnd,rcpath)
    --return dm_OBJ:YDM_Login("ycjl520", "weiyudns");
	-- ydm.YDM_SetAppInfo("2842", "378d9f20d3a9a534c40c68196cca1632");
	-- return ydm.YDM_Login("ycjl520", "weiyudns");

	local x = 0
	local y = 0
	local ret = ""
	local stable = {}	
	
	local myAccountTable = {}	
	
	myAccountTable = readAccount()
	dm_OBJ:SetPath(rcpath .. 'lua\\rc\\kingRobot\\')
	local bindret = dm_OBJ:BindWindow(tonumber(hwnd), "dx3", "windows3", "windows", 0)
	dm_OBJ:LuaSleep(2000)	
	
	
	inputLog("开始")
	
	fDate = readtxt(dm_OBJ,rcpath,hwnd,"Label_0")
	ftime = readtxt(dm_OBJ,rcpath,hwnd,"Label_1")

	
	
	for i = 1, #myAccountTable do
		local name = myAccountTable[i][1]
		inputLog(name)
		local password = myAccountTable[i][2]
		inputLog(password)
		--ret = "what"
		ret =QQLoadAccount(dm_OBJ,rcpath,hwnd,name,password)
		inputLog("登陆账号完毕")
		if ret == "余额不足" then		
			return "balance lacking"
		end
		dm_OBJ:LuaSleep(10000)		
		
		inputLog("准备喊话")
		--inputLog("喊话数据,内容:" .. fDate .. " 次数:" .. ftime)
		ret = Outcry(dm_OBJ,hwnd,fDate,tonumber(ftime))	
		inputLog("喊话完毕")
		--ret = yunDaMa(dm_OBJ,rcpath,hwnd)
		
		
		closeApp(dm_OBJ)
			
	end
	
	return(ret)
	



end
--Main(dm_OBJ,hwnd,rcpath)










